<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<head>
<c:set value="${pageContext.request.contextPath}" var="path"
	scope="page" />
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script type=text/javascript src="${path}/js/backstage_other.js"></script>
</head>

<!--问题管理-->
<div class="main_tag">求知广场管理>问题管理</div>
<div class="sysm1_udiv">
	<!--list-->
	<div style="width: 75%; float: left">
		<div class="tag_title">
			<i class="icon-list"> 问题列表</i>
		</div>
		<div style="width: 100%; float: left;">
			<c:choose>
				<c:when test="${empty(page.list)}">目前还未有人提问！</c:when>
				<c:otherwise>
					<table class="sysm1_utable" id="ques_table">
						<tr>
							<th>时间</th>
							<th>分类</th>
							<th>标题</th>
							<th>作者</th>
							<th>审核状态</th>
							
						</tr>
						<c:forEach var="question" items="${page.list}">
							<tr>
								<td>${question.time}</td>
								<td>${question.classify}</td>
								<td><a class="article" style="cursor:pointer;">${question.title}</a>
								<input type="hidden" value="${question.quesId}" id="article_id"  /></td>
								<td>${question.author}</td>
								<td>${question.checked==true?"<i class='icon-ok'></i>":"<i class='icon-remove'></i>"}</td>
								
							</tr>
						</c:forEach>

					</table>
					<!--分页-->
					<jsp:include page="pager.jsp"></jsp:include>
				</c:otherwise>
			</c:choose>
		</div>
	</div>

	<!--分类管理-->
	<div style="width: 20%; margin-left: 4%; float: left" id="classify">
		<div class="tag_title">
			<i class="icon-cogs"> 分类管理</i>
			<!--edit classify icon-->
			<i class="tag_right icon-cog" id="edit_classify"></i>
			<!--add new classify icon-->
			<i class="tag_right icon-plus" id="add_newclassfiy">&nbsp;</i>
			<!--隐藏框-->
			<span class="add_bg" style="display: none"> <input type="text"
				id="classify_add" value=""
				style="margin-left: 10px; margin-right: 10px; width: 130px;"><br>
				<button style="float: right; margin-top: 6px; margin-right: 10px"
					id="btn_newclassfiy">新增分类</button></span>
		</div>
		<!--内容-->
		<div style="width: 100%; float: left;">
			<table class="sysm1_utable" id="clas_table">
				<!--循环读取-->
				<c:forEach var="classify" items="${list}">
					<tr><td><span class="clas_name" id="clas_show">${classify.classify}</span>
								<!--hide--> 
							<span class="clas_name" id="clas_edit_box">
								<input type="hidden" value="${classify.id}" id="clas_edit_id"  />
								<input type="text" value="${classify.classify}" size="15"
									id="clas_edit_text" />
								<button id="sub_cedit" class="icon-ok"
									style="margin-left: 15px; border: none"></button>
							</span> <!--hidden end --> 
							<i class="clas_man icon-edit" id="clasicon_edit"></i> 
							<i class="clas_man icon-trash" id="clasicon_del"></i> 
							<span class="clas_del" id="clas_del" style="display:none;">
								<button id="btnclas_del">删除</button>
								<button id="btnclas_keep">保留</button>
							</span></td></tr>
				</c:forEach>
			</table>
		</div>
	</div>
</div>
<!-- add new classify js -->
<script type="text/javascript">
		/* ShowQuestionContentControllor*/
		 $("#ques_table").find("a.article").click(function(){
	 		 var quesId = $(this).next().val();
	 		$("#load").load("${path}/RedirectGetQuestion",{quesId:quesId});
		 });
	
		
		/*remove classify */
		$("#clas_table").find("button#btnclas_del").click(function(){
			var classify = $(this).parent().parent().find("span#clas_show").html();
			$.post("${path}/DeleteClassifyController", {
				classify:classify
			}, function(data) {
				alert(data);
			$("#load").load("${path}/ShowQuestionController",{x:0});
			});
		});
		
		/*add classify */
		$("#btn_newclassfiy").click(function() {
			var classify = $("#classify_add").val();
			$.post("${path}/AddClassifyController", {
				classify:classify
			}, function(data) {
				alert(data);
			$("#load").load("${path}/ShowQuestionController",{x:0});
			});
		});
		
		/*update classify */
		$("#clas_table").find("button#sub_cedit").click(function(){
			var classify = $(this).parent().find("#clas_edit_text").val();
			var id = $(this).parent().find("#clas_edit_id").val();
			$.post("${path}/UpdateClassifyController",{
				id:id,
				classify:classify
			},function(data){
				alert(data);
				$("#load").load("${path}/ShowQuestionController",{x:0});
				});	
			});
		
		/*classify other show */
		$("#clas_table").find("i#clasicon_edit").click(function(){
			$(this).parent().find("#clas_show").hide();
			$(this).parent().find("#clas_edit_box").show();
			$("i.clas_man").hide();
		});

		$("#clas_table").find("button.icon-ok").click(function(){
			$(this).parent().hide();
			$("#clas_table").find("#clas_show").show();
		});
		
		$("#clas_table").find("i#clasicon_del").click(function(){
			$(this).next("span#clas_del").slideToggle();
		});
		
		$("#clas_table").find("button#btnclas_keep").click(function(){
			$(this).parent().fadeOut(300);
		});

</script>